'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceChoosepeopleCtrl
 * @description
 * # FinanceChoosepeopleCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('FinanceChoosepeopleCtrl', function ($scope, $routeParams, Util,localStorageService, openApi, PagingService) {
        var relModuleObj;
        var param = {};
        // 获取搜索所需参数以及标题信息
        relModuleObj = Util.getDataforsearch();
        param.relatedModule = relModuleObj.selectTab;
        param = angular.extend(param, relModuleObj.param || {});
        // 选择后回传的数据
        var returnData;
        $scope.choosePeople = function (index) {
            $scope.submit(index)
        }
        $scope.submit = function (index) {
            var filterData;
            if ($scope.taskList.items) {
                // 返回的字段value
                // 如果把需要的key直接挂载在result上面则需要这个方法，否则不用过滤直接返回
                filterData = Util.filterSelectData($scope.taskList.items[index], $scope.taskList.valuePropertys, relModuleObj.propertyName)
                var pickerdata=localStorageService.get("pickerdata");
                if(pickerdata){
                  pickerdata=Object.assign(pickerdata,filterData);
                  localStorageService.set("pickerdata",pickerdata);
                }else{
                  relModuleObj.filterData = filterData;
                  Util.savaDataforsearch(relModuleObj);
                }
                Util.goBack();
            }
        }
        $scope.filterSql = param.filterSql;
        $scope.search = function (filterSql) {
            param.filterSql = filterSql;
            param.functionId=$routeParams.flag;
            $scope.taskList = new PagingService(openApi.getRelpage, param);
        }
        $scope.search();
    });